package lsgwr.exam.controller;

import io.swagger.annotations.ApiOperation;
import lsgwr.exam.component.SmsComponent;
import lsgwr.exam.utils.R;
import lsgwr.exam.vo.FormVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Random;
import java.util.UUID;

/**
 * @Description:
 * @Created: with IntelliJ IDEA.
 * @author: 夏沫止水
 * @createTime: 2020-06-27 10:04
 **/

@RestController
@RequestMapping(value = "/api/account")
public class SmsSendController {

    @Resource
    private SmsComponent smsComponent;

    /**
     * 提供给别的服务进行调用
     * @param formVo
     * @return
     */
    @PostMapping(value = "/sms")
    @ApiOperation("发送短信验证码")
    public R sendCode(@RequestBody FormVo formVo) {
        String code = generateCode();
        //String code = "abcd";
        //发送验证码
        //smsComponent.sendSmsCode(formVo.getPhone(),code);
        System.out.println("调用短信发送功能,验证码为："+code);
        return R.ok(code);
    }


    public String generateCode(){
        Random random = new Random();
        int number = random.nextInt(10000); // 生成[0,10000)之间的随机整数
        String code = String.format("%04d",number); // 将随机整激格式化4位字符串，不足4位在前面补
        return code;
    }


}

